﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static Dictionary<int, student> student = new Dictionary<int, student>();
        static student s1 = new student("1", 1, 1);
        static student s2 = new student("2", 2, 2);
        static void Main(string[] args)
        {
            student.Add(s1.num, s1);
            student.Add(s2.num, s1);
            one();
        }

        private static void one()
        {
            Console.WriteLine("1、添加学生信息；2、查询学生信息");
            int a = int.Parse(Console.ReadLine());
            switch (a)
            {
                case 1:
                    tianjia();
                    break;
                case 2:
                    chaxun();
                    break;
                default:
                    Console.WriteLine("输入有误，请重新输入！");
                    one();
                    break;
            }
        }

        private static void chaxun()
        {
            Console.WriteLine("1、查询所有（按学号排序）2、查询所有（按姓名排序）3、查询所有（按年龄排序）4、按学号查询（查没有，则打印查无此学生）5、退出");
            int a = int.Parse(Console.ReadLine());
            switch (a)
            {
                case 1:
                    List<student> num2 = student.Values.ToList<student>();
                    num2.Sort(new num());
                    two(num2);
                    one();
                    break;
                case 2:
                    List<student> name2 = student.Values.ToList<student>();
                    name2.Sort(new name());
                    two(name2);
                    one();
                    break;
                case 3:
                    List<student> age2 = student.Values.ToList<student>();
                    age2.Sort(new age());
                    two(age2);
                    one();
                    break;
                case 4:
                    Console.WriteLine("请输入要查询学生的学号：");
                    int id = int.Parse(Console.ReadLine());
                    if (student.ContainsKey(id))
                    {
                        Console.WriteLine(student[id]);
                    }
                    else
                    {
                        Console.WriteLine("查无此学生！");
                        one();
                    }
                    break;
                case 5:
                    Environment.Exit(0);
                    break;
                default:
                    break;
            }
        }
        private static void two(List<student> list)
        {
            foreach (student s in list)
            {
                Console.WriteLine(s);
            }

        }

        private static void tianjia()
        {
            student s = new student();
            Console.WriteLine("请输入学生的姓名");
            s.name = Console.ReadLine();
            Console.WriteLine("请输入学生的年龄");
            s.age = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入学生学号");
            s.num = int.Parse(Console.ReadLine());
            if (student.ContainsKey(s.num))
            {
                Console.WriteLine("重复的学号！");
            }
            else
            {
                student[s.num] = s;
            }
            one();
        }
    }
}